package com.tarena.tocketmq.consumer;

import com.tarena.tocketmq.service.HelloService;
import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Slf4j
@Component
@RocketMQMessageListener(
        topic = "topic01",
        consumerGroup = "test-consumer-group"
//        selectorExpression = "*",
//        messageModel = MessageModel.CLUSTERING
)
public class MyConsumerListener implements RocketMQListener<String> {
    @Autowired
    private HelloService helloService;
    @Override
    public void onMessage(String name) {
        //todo 消费逻辑
        String result = null;
        try {
            result = helloService.sendMsg(name);
        } catch (RuntimeException e){
            log.error("consumer获取消息失败：{}", e.getMessage());
        }
        log.info("consumer获取消息：{}", result);
    }
}
